package com.iknow.ui.model;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.iknow.data.IdentityFlag;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IndentityFlagAdapter extends BaseAdapter
{
  private List<IdentityFlag> mFlagList;
  private LayoutInflater mInflater = null;

  public IndentityFlagAdapter(LayoutInflater paramLayoutInflater)
  {
    this.mFlagList = new ArrayList();
    this.mInflater = paramLayoutInflater;
  }

  private boolean bExits(IdentityFlag paramIdentityFlag)
  {
    int i = 0;
    while (true)
    {
      int j;
      if (i >= this.mFlagList.size())
        j = 0;
      while (true)
      {
        return j;
        IdentityFlag localIdentityFlag = (IdentityFlag)this.mFlagList.get(i);
        if (!(localIdentityFlag.getName().equalsIgnoreCase(paramIdentityFlag.getName())))
          break;
        this.mFlagList.remove(i);
        paramIdentityFlag.setSelected(localIdentityFlag.IsFlagSelected());
        this.mFlagList.add(0, paramIdentityFlag);
        j = 1;
      }
      ++i;
    }
  }

  private void fillDataToView(int paramInt, View paramView)
  {
    IdentityFlag localIdentityFlag = getItem(paramInt);
    if (localIdentityFlag.IsFlagSelected())
      paramView.setBackgroundResource(2130837574);
    while (true)
    {
      ((ViewHodler)paramView.getTag()).txt.setText(localIdentityFlag.getName());
      return;
      paramView.setBackgroundResource(2130837572);
    }
  }

  private View newView()
  {
    View localView = this.mInflater.inflate(2130903114, null);
    ViewHodler localViewHodler = new ViewHodler(this, null);
    localViewHodler.txt = ((TextView)localView.findViewById(2131296458));
    localView.setTag(localViewHodler);
    return localView;
  }

  public void addFlag(IdentityFlag paramIdentityFlag)
  {
    if (bExits(paramIdentityFlag));
    while (true)
    {
      while (true)
      {
        return;
        if (!(paramIdentityFlag.IsFlagSelected()))
          break;
        this.mFlagList.add(0, paramIdentityFlag);
      }
      this.mFlagList.add(paramIdentityFlag);
    }
  }

  public int getCount()
  {
    return this.mFlagList.size();
  }

  public String getFlags()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    Iterator localIterator = this.mFlagList.iterator();
    while (true)
    {
      IdentityFlag localIdentityFlag;
      do
      {
        if (!(localIterator.hasNext()))
        {
          if (localStringBuilder.length() > 0)
            localStringBuilder.replace(localStringBuilder.length() - 1, localStringBuilder.length(), "");
          return localStringBuilder.toString();
        }
        localIdentityFlag = (IdentityFlag)localIterator.next();
      }
      while (!(localIdentityFlag.IsFlagSelected()));
      localStringBuilder.append(localIdentityFlag.getName());
      localStringBuilder.append("，");
    }
  }

  public IdentityFlag getItem(int paramInt)
  {
    return ((IdentityFlag)this.mFlagList.get(paramInt));
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    if (paramView == null)
      paramView = newView();
    fillDataToView(paramInt, paramView);
    return paramView;
  }

  private class ViewHodler
  {
    ImageView img;
    TextView txt;
  }
}